/*
 * @(#)InitConfigServlet.java 1.0 2005-3-2
 * Copyright 2005 VandaGroup, Inc. All rights reserved.
 */
package com.vandagroup.portal.util;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.vanda.db.DBFactory;
import com.vanda.db.HQLAccessor;
import com.vanda.db.cache.CodeLoad;
import com.vanda.db.exception.DbException;
import com.vanda.util.LogFunc;

/*******************************************************************************
 * 类说明: 初始化Servlet
 * <P>
 * 
 * @author 蒋勇
 *         <P>
 * @version 1.0 2005-3-2
 */
public class InitConfigServlet extends javax.servlet.http.HttpServlet {
	/**
	 * 刷新代码表doGet方式（集群环境需要在每台服务器上运行刷新）
	 * 
	 * @param request
	 * @param response
	 * @return 无
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			initCodeInfo();
		} catch (Exception e) {
			LogFunc.error(e);
		}
	}

	/**
	 * 刷新代码表doPost方式（集群环境需要在每台服务器上运行刷新）
	 * 
	 * @param request
	 * @param response
	 * @return 无
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			initCodeInfo();
		} catch (Exception e) {
			LogFunc.error(e);
		}
	}

	/**
	 * <B>Describe：初始化方法，调用一些必要的过程 </B>
	 * 
	 * @param config
	 */
	public void init(ServletConfig config) {
		try {
			//initCodeInfo();
			super.init(config);
		} catch (Exception e) {
			LogFunc.error(e);
		}
	}

	/**
	 * 方法说明: 初始化系统代码表
	 *  
	 */
	public void initCodeInfo() {
		CodeLoad _codeLoad = new CodeLoad();
		HQLAccessor accessor = null;
		try {
			accessor = DBFactory.getHQLAccessor();
			//_codeLoad.configure() ;
			//CodeLoad.readCodeFormDB(accessor.getSession().connection());
		} catch (Exception e) {
			LogFunc.error(e);
		} finally {
			if (accessor != null) {
				try {
					accessor.close();
				} catch (DbException e1) {
					LogFunc.error(e1);
				}
			}
		}
	}

}